/**
 * 
 */

/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  basicprocess;

import java.util.Hashtable;
import java.util.Map;
import java.util.Vector;

import control.RequestParameter;

import pool.tablename.Property_details;
import pool.tablename.Pool;


import utility.CapitalChar;
import utility.ConvertToLower;
import utility.Input;

import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;

/**
 * @author POOL
 *
 */
public class Inheritance implements Basicprocessinterface 
{
	DBManager database;
	Hashtable<Object, Object>Mastermap= new Hashtable<Object, Object>();
	Vector< Object>propertyVector = new Vector<Object>();
	String INHEITANCE ="inheritance";
	String REF="ref";
	GetIdName gid;
	Pool pool;
	Vector<Object>Inheritance = new Vector<Object>();
	basicprocess.inheritance.Inheritance inheritance;
	
	public Hashtable<Object, Object> getMasterHashtabel()
	{
		return Mastermap;
	}

	public Vector<Object> getpropertydetailsVector() 
	{
		return propertyVector;
	}
	
	public void Init() 
	{	
		gid = new GetIdName();
		INHEITANCE = gid.getId(INHEITANCE);
	}


	
	public void setObject(Object obj) 
	{	
		pool = (Pool) obj;
	}

	public void getInsert() 
	{	
		Mastermap = pool.getHashtabel();
		propertyVector = pool.getpropertyVector();
		Hashtable<Object, Object> propertydetailstabel = new Hashtable<Object, Object>();
		for(int i=0;i<propertyVector.size();i++)
		{
			Property_details pd = (Property_details)propertyVector.get(i);
			propertydetailstabel.putAll((Hashtable<Object, Object>)  ConvertToLower.convertHashKey(pd.PropertyMap));
			System.out.println(propertydetailstabel.get("pid"));
			if(propertydetailstabel.get("pid").equals(INHEITANCE))
			{	
				propertydetailstabel.putAll((Hashtable<Object, Object>)  ConvertToLower.convertHashKey(pd.PropertyMap));
				
				try 
				{
					String typeofinheritances = gid.getItem(propertydetailstabel.get("ref").toString());
					Class c = Class.forName("basicprocess.inheritance."+CapitalChar.makeFirstCharCapital(typeofinheritances));
					inheritance = (basicprocess.inheritance.Inheritance) c.newInstance();
					inheritance.InitPool();
					inheritance.setobject(pool);	
					inheritance.getInsert();
					inheritance.getpropertydetailsVector();
				}
				catch (ClassNotFoundException e) 
				{
					e.printStackTrace();
				}
				catch (InstantiationException e) 
				{
					e.printStackTrace();
				}
				catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		}
	}

	public void getUpdate() 
	{	
		Mastermap = pool.getHashtabel();
		RecordSearch search =new RecordSearch();
		Hashtable<Object, Object>table = new Hashtable<Object, Object>();
		table.put("pid", INHEITANCE);
		table.put("pv", gid.getId(Mastermap.get("name").toString()));
		table.put("td", "null");
		String line [] = search.getArrayFromResultSet();
		try 
		{
			String splitline[] = line[0].split("\t");
			String typeofinheritances = gid.getItem(splitline[Column.ref_index-1]);					
			Class c = Class.forName("basicprocess.inheritance."+CapitalChar.makeFirstCharCapital(typeofinheritances));
			inheritance = (basicprocess.inheritance.Inheritance) c.newInstance();
			inheritance.InitPool();
			inheritance.setobject(pool);	
			inheritance.getUpdate();
			inheritance.getpropertydetailsVector();
		}
		catch (ClassNotFoundException e) 
		{
			e.printStackTrace();
		}
		catch (InstantiationException e) 
		{
			e.printStackTrace();
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		}
		

	public void processBasicprocess() {
		// TODO Auto-generated method stub
		
	}

	public Hashtable<Object, Object> getHashtable() {
		// TODO Auto-generated method stub
		return new Hashtable<Object, Object>();
	}

	public void setMasterHashtabel(Hashtable<Object, Object> MasterMap) 
	{
		this.Mastermap.putAll(MasterMap);
	}

	public void setpropertydetailsVector(Vector<Object> PropertyMap) 
	{
		this.propertyVector.addAll(PropertyMap);
	}

	public void setRequestParameter(RequestParameter req) {
		// TODO Auto-generated method stub
		
	}

	public void setType(String type) {
		// TODO Auto-generated method stub
		
	}

	public void setTablename(String tablename) {
		// TODO Auto-generated method stub
		
	}
		
		
		
		
	
/*		for(int i=0;i<Inheritance.size();i++)
		{
			Inheritance inheritance = (Inheritance) Inheritance.get(i);
			inheritance.inheritance.getUpdate();
			inheritance.inheritance.getpropertydetailsVector();
		}*/
	/*public void processBasicprocess()
	{
		Mastermap = pool.getHashtabel();
		propertyVector = pool.getpropertyVector();
		Hashtable<Object, Object> propertydetailstabel = new Hashtable<Object, Object>();
		for(int i=0;i<propertyVector.size();i++)
		{
			PropertyDetails pd = (PropertyDetails)propertyVector.get(i);
			propertydetailstabel.putAll((Hashtable<Object, Object>)  ConvertToLower.convertHashKey(pd.PropertyMap));
			System.out.println(propertydetailstabel.get("pid"));
			if(propertydetailstabel.get("pid").equals(INHEITANCE))
			{	
				propertydetailstabel.putAll((Hashtable<Object, Object>)  ConvertToLower.convertHashKey(pd.PropertyMap));
				
				try 
				{
					String typeofinheritances = gid.getItem(propertydetailstabel.get("ref").toString());
					
					Class c = Class.forName("basicprocess.inheritance."+CapitalChar.makeFirstCharCapital(typeofinheritances));
					inheritance = (basicprocess.inheritance.Inheritance) c.newInstance();
					inheritance.setDbmanager(database);
					inheritance.setobject(pool);
					Inheritance.add(this);
					
					inheritance.processInheitance();
					inheritance.getpropertydetailsVector();
				catch (ClassNotFoundException e) 
				{
					e.printStackTrace();
				}
				catch (InstantiationException e) 
				{
					e.printStackTrace();
				}
				catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		}	
	}*/

	}
	

